package net.blf2.mybatisplus.config;

import com.baomidou.mybatisplus.core.config.GlobalConfig;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import net.blf2.mybatisplus.sqlinject.UserInjector;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement;

@Configuration
@EnableTransactionManagement
@MapperScan(basePackages = {"net.blf2.mybatisplus.mapper"})
public class MybatisPlusConfig {

    /**
     * 分页插件
     */
    @Bean
    public PaginationInterceptor paginationInterceptor() {
        return new PaginationInterceptor();
    }

    @Bean
    public GlobalConfig globalConfig(){

        GlobalConfig globalConfig = new GlobalConfig();
        globalConfig.setSqlInjector(userInjector());
        return globalConfig;
    }

    @Bean
    public UserInjector userInjector(){

        return new UserInjector();
    }
}
